using System;
using System.IO;
using System.Collections.Generic;
using Hymans.Charles.JAudit.SyntaxNodes;

namespace Hymans.Charles.JAudit
{
	public class Analysis
	{
		private Parser parser;
		
		internal Analysis(Stream stream)
		{
			// TODO: would have been better if the Scanner were built over a reader, that way it would 
			// have been easy to plug either a string or a file
			// TODO: check in the documentation of gplex if it can not be the case...
			Scanner scanner = new Scanner(stream);
			this.parser = new Parser(scanner);
		}
		
		public Analysis(string input)
		{
			Scanner scanner = new Scanner();
			scanner.SetSource(input, 0);
			this.parser = new Parser(scanner);
		}
		
		public List<Warning> Perform()
		{
			this.parser.Parse();
		 	JavaFile syntaxTree = this.parser.Result;
			Visitor visitor = new Visitor();
			syntaxTree.Visit(visitor);
			return visitor.Warnings;
		}
	}
}

